function [ conCompMaxVals ] = getVelocityManuallyGUI( smoothedVelData, windowedImg, conCompMaxVals, inputAxes, instructionText )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

%Obtain control points input from user
set(instructionText, 'string', strcat('Click along the outline of the velocity waveform.', ...
    ' For the last point that you intend to place, right click where you would like to place', ...
    ' it instead of left clicking.'));
axes(inputAxes)
[x,y] = getpts;
ptsMatrix = [x y];

[vals,I]=sort(ptsMatrix(:,1)); %sort the input points so as not to mess up the next steps
ptsMatrix=ptsMatrix(I,:);

%Creates new curve made up of connected line segments with endpoints at
%each obtained point
xMatrix = [];
yMatrix = [];
sizePtsMatrix = size(ptsMatrix);
for i=1:sizePtsMatrix - 1
    point1 = ptsMatrix(i,:);
    point2 = ptsMatrix(i+1,:);
    xBounds = [point1(1),point2(1)];
    yBounds = [point1(2),point2(2)];
    xVect = (point1(1):point2(1));
    %If any chosen points are vertical, recursively calls this function until
    %a set of points is chosen with no vertical elements
    try
        yVect = (interp1(xBounds,yBounds,xVect));
    catch ME
        msg = msgbox(strcat('Please try selecting points again and ensure', ...
            ' that no chosen points are vertical to each other.'),'Instructions');
        [ conCompMaxVals ] = getVelocityManuallyGUI( smoothedVelData, windowedImg, conCompMaxVals, inputAxes, instructionText );
        return   
    end
    yVect = (round(yVect));
    
    %removes repeat x values where obtained points are
    if i == 1
        xMatrix = [xMatrix, xVect];
        yMatrix = [yMatrix, yVect];
    else
        xMatrix = [xMatrix, xVect(2:end)];
        yMatrix = [yMatrix, yVect(2:end)];
    end
end
ptsMatrixExtended = [transpose(xMatrix), transpose(yMatrix)];


%Replace max velocity values
sizePtsMatrixExtended = size(ptsMatrixExtended);
replaceStartVal = ptsMatrixExtended(1,1);
replaceEndVal = replaceStartVal+sizePtsMatrixExtended(1)-1;
conCompMaxVals(replaceStartVal:replaceEndVal,2) = ptsMatrixExtended(:,2);

end


